package com.lazydong.apiforward.clientupdate;

import cn.hutool.core.io.FileUtil;
import com.lazydong.apiforward.clientupdate.constant.UpdateConstant;
import com.lazydong.apiforward.clientupdate.gui.UpdateMainApp;
import com.lazydong.apiforward.clientupdate.util.KillClientUtil;

import java.nio.charset.StandardCharsets;

/**
 * 客户端更新辅助程序
 */
public class ApiForwardClientUpdate {
    public static void main(String[] args) {
        killClient();
        UpdateMainApp updateMainApp = new UpdateMainApp();
        updateMainApp.run();
    }

    private static void killClient() {
        if (!FileUtil.exist(UpdateConstant.CLIENT_PID_PATH)) {
            return;
        }
        String pid = FileUtil.readString(UpdateConstant.CLIENT_PID_PATH, StandardCharsets.UTF_8);
        KillClientUtil.killByPid(pid);
    }
}
